#coding=utf-8
import urllib, datetime, time
from BeautifulSoup import BeautifulSoup 
import MySQLdb as m
import settings

def get_soup(url):
    import socket
    socket.setdefaulttimeout(10)
    while True:
        try:
            f = urllib.urlopen(url)
            htmltext = f.read().decode('gb18030', 'ignore')
            s = BeautifulSoup(htmltext) 
            return s
        except (socket.timeout,IOError), e:
            print url, e
            time.sleep(0.05)

def get_date_isostr(y,m,d):
    return datetime.date(y,m,d).isoformat()
def get_today_isostr():
    return datetime.date.today().isoformat()
def get_date_sohustr(y,m,d):
    isostr = get_date_isostr(y,m,d)
    return ''.join(isostr.split('-'))
def get_today_shoustr():
    isostr = get_today_isostr()
    return ''.join(isostr.split('-'))

def get_db_connector():
    ''''''
    con = m.connect(host='localhost', user='root', db='shstock')
    return con
